package com.core.fragment;

import com.core.CoreApplication;
import com.core.activity.BaseActivity;
import com.core.util.file.SharedPreferenceUtil;
import com.core.wigets.Alert;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * 非public.用的时候直接拷贝到子项目中。用法同 {@link BaseActivity} 一样
 *
 * @author 李澄锋<br>
 * 2014年9月19日下午3:42:50
 */
public abstract class BaseFragment extends FrameBaseFragment {

    public abstract String getFragmentName();

    @Override
    protected void findViewById() {
        super.findViewById();
    }

    public boolean isEmpty(Object str) {
        if (str == null || str.toString().trim().length() == 0) {
            return true;
        } else {
            return false;
        }
    }


    public String getJsonValue(Object jsonStr, String key) {
        try {
            JSONObject json = new JSONObject(jsonStr + "");
            return json.getString(key);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return "";
    }

    public void showToast(String content) {
        Alert.toast(content);
    }

    public void setSharedPref(String key, String value) {
        SharedPreferenceUtil.saveString(CoreApplication.getContext(), key, value);
    }

    protected String getSharedPref(String key) {
        return SharedPreferenceUtil.getString(CoreApplication.getContext(), key);
    }
}
